<?php 
 
add_filter('automatic_updater_disabled', '__return_true');      // 关闭更新检查定时作业
remove_action('init', 'wp_schedule_update_checks');             // 移除已有的版本检查定时作业
wp_clear_scheduled_hook('wp_version_check');                    // 移除已有的插件更新定时作业
wp_clear_scheduled_hook('wp_update_plugins');                   // 移除已有的主题更新定时作业
wp_clear_scheduled_hook('wp_update_themes');                    // 移除已有的自动更新定时作业
wp_clear_scheduled_hook('wp_maybe_auto_update');                // 移除后台内核更新检查
remove_action('admin_init', '_maybe_update_core');
// 移除后台插件更新检查
remove_action('load-plugins.php', 'wp_update_plugins');
remove_action('load-update.php', 'wp_update_plugins');
remove_action('load-update-core.php', 'wp_update_plugins');
remove_action('admin_init', '_maybe_update_plugins');
// 移除后台主题更新检查
remove_action('load-themes.php', 'wp_update_themes');
remove_action('load-update.php', 'wp_update_themes');
remove_action('load-update-core.php', 'wp_update_themes');
remove_action('admin_init', '_maybe_update_themes');





// Exit if accessed directly
//禁止wptexturize函数
remove_filter('the_content', 'wptexturize');
remove_action('pre_post_update', 'wp_save_post_revision' );
// end
// 清除头部无用信息,已知BUG,禁用将导致Query Monitor插件不正常显示
// remove_action( 'wp_head', 'wp_enqueue_scripts', 1 );
//Javascript的调用
remove_action( 'wp_head', 'feed_links', 2 );
//移除feed
remove_action( 'wp_head', 'feed_links_extra', 3 );
//移除feed
remove_action( 'wp_head', 'rsd_link' );
//移除离线编辑器开放接口
remove_action( 'wp_head', 'wlwmanifest_link' );
//移除离线编辑器开放接口
remove_action( 'wp_head', 'index_rel_link' );
//去除本页唯一链接信息
remove_action('wp_head', 'parent_post_rel_link', 10, 0 );
//清除前后文信息
remove_action('wp_head', 'start_post_rel_link', 10, 0 );
//清除前后文信息
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action( 'wp_head', 'locale_stylesheet' );
remove_action('publish_future_post','check_and_publish_future_post',10, 1 );
remove_action( 'wp_head', 'noindex', 1 );
remove_action( 'wp_head', 'wp_print_styles', 8 );
//载入css
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
remove_action( 'wp_head', 'wp_generator' );
//移除WordPress版本
remove_action( 'wp_head', 'rel_canonical' );
remove_action( 'wp_footer', 'wp_print_footer_scripts' );
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
add_action('widgets_init', 'my_remove_recent_comments_style');
function my_remove_recent_comments_style() {
	global $wp_widget_factory;
	remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'] ,'recent_comments_style'));
}
// end
//~ 页面链接后添加反斜杠
function itbulu_nice_trailingslashit($string, $type_of_url) {
	if ($type_of_url != 'single')
		$string = trailingslashit($string);
	return $string;
}
add_filter('user_trailingslashit', 'itbulu_nice_trailingslashit', 10, 2);
//禁止emojis Edit By laobuluo.com
function disable_emojis() {
	remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
	remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
	remove_action( 'wp_print_styles', 'print_emoji_styles' );
	remove_action( 'admin_print_styles', 'print_emoji_styles' );
	remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
	remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
	remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
	add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
}
add_action( 'init', 'disable_emojis' );
function disable_emojis_tinymce( $plugins ) {
	if ( is_array( $plugins ) ) {
		return array_diff( $plugins, array( 'wpemoji' ) );
	} else {
		return array();
	}
}
//去除加载的css和js后面的版本号 Edit By laobuluo.com
function sb_remove_script_version( $src ) {
	$parts = explode( '?', $src );
	return $parts[0];
}
add_filter( 'script_loader_src', 'sb_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', 'sb_remove_script_version', 15, 1 );
// 禁止自PING和版本保存
function no_self_ping( &$links ) {
	$home = get_option( 'home' );
	foreach ( $links as $l => $link )
		if ( 0 === strpos( $link, $home ) )
		unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
remove_action('pre_post_update', 'wp_save_post_revision');
add_action('wp_print_scripts', 'disable_autosave');
function disable_autosave() {
	wp_deregister_script('autosave');
}
//强制jquery库文件底部载入 Edit By laobuluo.com
function ds_print_jquery_in_footer( &$scripts) {
	if ( ! is_admin() )
	        $scripts->add_data( 'jquery', 'group', 1 );
}
add_action( 'wp_default_scripts', 'ds_print_jquery_in_footer' );
// 关闭 XML-RPC 功能  Edit By laobuluo.com
add_filter('xmlrpc_enabled', '__return_false');
// 屏蔽 REST API
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');
//移除头部 wp-json 标签和 HTTP header 中的 link Edit By laobuluo.com
remove_action('wp_head', 'rest_output_link_wp_head', 10 );
remove_action('template_redirect', 'rest_output_link_header', 11 );
//禁止Gutenberg编辑器
add_filter('use_block_editor_for_post', '__return_false');
remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
// 禁止主页新闻
function disable_dashboard_widgets() {
	remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
	//近期评论 
	remove_meta_box('dashboard_recent_drafts', 'dashboard', 'normal');
	//近期草稿
	remove_meta_box('dashboard_primary', 'dashboard', 'core');
	//wordpress博客  
	remove_meta_box('dashboard_secondary', 'dashboard', 'core');
	//wordpress其它新闻  
	remove_meta_box('dashboard_right_now', 'dashboard', 'core');
	//wordpress概况  
	remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
	//wordresss链入链接  
	remove_meta_box('dashboard_plugins', 'dashboard', 'core');
	//wordpress链入插件  
	remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
	//wordpress快速发布
}
add_action('admin_menu', 'disable_dashboard_widgets');
// 取消WordPress评论框下的'HTML 标签和属性
add_filter( 'pre_comment_content', 'wp_specialchars' );
// 停用wordpress的链接猜测功能
add_filter('redirect_canonical', 'stop_guessing');
function stop_guessing($url) {
	if (is_404()) {
		return false;
	}
	return $url;
}
// 禁用主题编辑器和插件编辑器
function disable_mytheme_action() {
	define('DISALLOW_FILE_EDIT', TRUE);
}
add_action('init', 'disable_mytheme_action');
// 禁用embed 
function disable_embeds_init() {
	/* @var WP $wp */
	global $wp;
	// Remove the embed query var.
	$wp->public_query_vars = array_diff( $wp->public_query_vars, array(
	 'embed',
	 ) );
	// Remove the REST API endpoint.
	remove_action( 'rest_api_init', 'wp_oembed_register_route' );
	// Turn off
	add_filter( 'embed_oembed_discover', '__return_false' );
	// Don't filter oEmbed results.
	remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
	// Remove oEmbed discovery links.
	remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
	// Remove oEmbed-specific JavaScript from the front-end and back-end.
	remove_action( 'wp_head', 'wp_oembed_add_host_js' );
	add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' );
	// Remove all embeds rewrite rules.
	add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
}
add_action( 'init', 'disable_embeds_init', 9999 );
/**
 * Removes the 'wpembed' TinyMCE plugin.
 *
 * @since 1.0.0
 *
 * @param array $plugins List of TinyMCE plugins.
 * @return array The modified list.
 */
function disable_embeds_tiny_mce_plugin( $plugins ) {
	return array_diff( $plugins, array( 'wpembed' ) );
}
/**
 * Remove all rewrite rules related to embeds.
 *
 * @since 1.2.0
 *
 * @param array $rules WordPress rewrite rules.
 * @return array Rewrite rules without embeds rules.
 */
function disable_embeds_rewrites( $rules ) {
	foreach ( $rules as $rule => $rewrite ) {
		if ( false !== strpos( $rewrite, 'embed=true' ) ) {
			unset( $rules[ $rule ] );
		}
	}
	return $rules;
}
/**
 * Remove embeds rewrite rules on plugin activation.
 *
 * @since 1.2.0
 */
function disable_embeds_remove_rewrite_rules() {
	add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
	flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );
/**
 * Flush rewrite rules on plugin deactivation.
 *
 * @since 1.2.0
 */
function disable_embeds_flush_rewrite_rules() {
	remove_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
	flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'disable_embeds_flush_rewrite_rules' );
// 禁用gravatar并用默认头像替换
define('DEFAULT_AVATAR_URL', get_template_directory_uri() . '/default.jpg');
//默认头像
function no_gravatars( $avatar ) {
	return preg_replace( "/http.*?gravatar\.com[^\']*/", DEFAULT_AVATAR_URL, $avatar );
}
add_filter( 'get_avatar', 'no_gravatars' );

// 对svg和webp的支持
function flybird_mime_types( $mimes ){
	$mimes['svg'] = 'image/svg+xml';
	$mimes['webp'] = 'image/webp';
	return $mimes;
}
add_filter( 'upload_mimes', 'flybird_mime_types');

// 禁用所有文章类型的修订版本

add_filter( 'wp_revisions_to_keep', 'specs_wp_revisions_to_keep', 10, 2 );
function specs_wp_revisions_to_keep( $num, $post ) {
return 0;
}
 
?>